<?php
namespace Admin\Controller;
use Think\Controller;
use Admin\Model\SysUserModel;
use Common\Controller\CommonController;
/**
 * admin 基类控制器
 */
class LoginController extends CommonController{
	/**
	 * 初始化方法
	 */
	public function _initialize(){
// 		parent::_initialize();
	}
	public function index(){
		if($_POST){
			$username=I('username',null);
			$password=I('password',null);
			$Sys_User=SysUserModel::newSelf();
			if(empty($username)||empty($password)){
			    $this->ajaxReturn(['code'=>false,'msg'=>'管理员账号或密码不能为空']);
			}
			$admin=$Sys_User->findByUserName($username);
			if (!$admin) {
			    $this->ajaxReturn(['code'=>false,'msg'=>'管理员账号或密码错误']);
			}
			if(!$Sys_User->verificationPassWord($password, $admin['pwd'])){
			    $this->ajaxReturn(['code'=>false,'msg'=>'管理员账号或密码错误']);
			}
			session('sys_user',$admin);
			$this->ajaxReturn(['code'=>true,'msg'=>'登录成功']);
		}
		if(session('?sys_user')){
			$this->redirect('Index/index');
		}
		$this->display();
	}
	public function loginOut(){
		session('sys_user',null);
		$this->success('退出成功','index');
	}
	public function checkVerify($code, $id = ''){
		$verify = new \Think\Verify();
		return $verify->check($code,$id);
	}
    public function getVerify(){
		$config =    array(
			'fontSize'    =>    15,    // 验证码字体大小
			'length'      =>    4,     // 验证码位数
			'useNoise'    =>    false, // 关闭验证码杂点
		);
		$Verify = new \Think\Verify($config);
		$Verify->entry();
	}
	
}

